package rpc

import (
	"fmt"
	"github.com/cloudwego/kitex/client"
	"github.com/flairamos/go-component/nacos"
	"github.com/nacos-group/nacos-sdk-go/vo"
	"order/rpc/orderclient"
)

func Client() orderclient.RPCClient {
	rpcClient, err := orderclient.NewRPCClient("orderserver", client.WithHostPorts("192.168.5.118:10000"))
	if err != nil {
		panic(err)
	}
	return rpcClient
}

func ClientFormNacos() orderclient.RPCClient {
	var param = vo.SelectOneHealthInstanceParam{
		Clusters:    []string{"test"},
		ServiceName: "test_app1",
		GroupName:   "dev_food_platform",
	}
	config := nacos.DefaultClient("public", "mysql", "dev_food_platform", nil)
	instance, err := nacos.SelectOneHealthyInstance(config, param)
	if err != nil {
		panic(err)
	}
	addr := fmt.Sprintf("%s:%d", instance.Ip, instance.Port)
	rpcClient, err := orderclient.NewRPCClient("test_app1", client.WithHostPorts(addr))
	return rpcClient
}
